/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utn.tsb.tej.world_logic;

import java.lang.reflect.Array;
import java.util.Arrays;
import csm.uttils.generics.Roster;

/**
 *
 * @author Administrator
 */
public class SituationCrisis extends Situation{

    private Roster<Player> crisisPlayers=new Roster<Player>();

    public Roster<Player> getCrisisPlayers() {
        return crisisPlayers;
    }
    private int[] rolls;

    public SituationCrisis(String name, String descripcion) {
        super(name, descripcion);
        
    }

    private int getRoll() {
        return ((int) (Math.random() * 6)) + 1;
    }

    @Override
    public boolean init(Roster<Player> players) {
       int roll;
        rolls = new int[players.count()];
        for (int i = 0; i < players.count(); i++) {
            roll = getRoll();
            players.getElementInPosition(i).setRoll(roll);
            rolls[i] = roll;
        }
        Arrays.sort(rolls);
        int min = rolls[0];
        for (int i = 0; i < players.count(); i++) {
            if (players.getElementInPosition(i).getRoll() == min) {
                crisisPlayers.addInOrder(players.getElementInPosition(i));
            }
        }
        return true;

    }
}
